package com.haoshuang.zhouzhoubang.ui.page.shop.confirm

import androidx.lifecycle.rxLifeScope
import com.haoshuang.zhouzhoubang.base.request
import com.haoshuang.zhouzhoubang.model.bean.OrderShopBean
import com.haoshuang.zhouzhoubang.model.bean.WxPayBean
import com.haoshuang.zhouzhoubang.model.bean.ZfbBean
import com.mufeng.libs.base.BaseViewModel
import com.mufeng.libs.state.StateData
import com.mufeng.libs.state.StatefulMutableLiveData

class OrderQrViewModel : BaseViewModel() {

    /**
     * 立即购买的支付宝支付
     */
    val getData2New = StatefulMutableLiveData<ZfbBean>()
    fun getData2New(vararg params: Pair<String, Any?>) {
        rxLifeScope.launch {
            request<ZfbBean>("api/goods/create_order_new", *params,
                onStart = {
                    getData2New.value = StateData.Loading
                },
                onError = { code, msg ->
                    getData2New.value = StateData.Error(code, msg)
                }, onSuccess = {
                    getData2New.value = StateData.Success(it)
                })
        }
    }

    /**
     * 立即购买的微信支付
     */
    val getData33New = StatefulMutableLiveData<WxPayBean>()
    fun getData33New(vararg params: Pair<String, Any?>) {
        rxLifeScope.launch {
            request<WxPayBean>("api/goods/create_order_new", *params,
                onStart = {
                    getData33New.value = StateData.Loading
                },
                onError = { code, msg ->
                    getData33New.value = StateData.Error(code, msg)
                }, onSuccess = {
                    getData33New.value = StateData.Success(it)
                })
        }
    }

    val getData2 = StatefulMutableLiveData<ZfbBean>()
    fun getData2(vararg params: Pair<String, Any?>) {
        rxLifeScope.launch {
            request<ZfbBean>("api/goods/create_order", *params,
                onStart = {
                    getData2.value = StateData.Loading
                },
                onError = { code, msg ->
                    getData2.value = StateData.Error(code, msg)
                }, onSuccess = {
                    getData2.value = StateData.Success(it)
                })
        }
    }

    val getData33 = StatefulMutableLiveData<WxPayBean>()
    fun getData33(vararg params: Pair<String, Any?>) {
        rxLifeScope.launch {
            request<WxPayBean>("api/goods/create_order", *params,
                onStart = {
                    getData33.value = StateData.Loading
                },
                onError = { code, msg ->
                    getData33.value = StateData.Error(code, msg)
                }, onSuccess = {
                    getData33.value = StateData.Success(it)
                })
        }
    }

    val getData = StatefulMutableLiveData<OrderShopBean>()
    fun getData(vararg params: Pair<String, Any?>) {
        rxLifeScope.launch {
            request<OrderShopBean>("api/goods/product_confirm_order", *params,
                onStart = {
                    getData.value = StateData.Loading
                },
                onError = { code, msg ->
                    getData.value = StateData.Error(code, msg)
                }, onSuccess = {
                    getData.value = StateData.Success(it)
                })
        }
    }

    val getData3 = StatefulMutableLiveData<OrderShopBean>()
    fun getData3(vararg params: Pair<String, Any?>) {
        rxLifeScope.launch {
            request<OrderShopBean>("api/goods/car_confirm_order", *params,
                onStart = {
                    getData3.value = StateData.Loading
                },
                onError = { code, msg ->
                    getData3.value = StateData.Error(code, msg)
                }, onSuccess = {
                    getData3.value = StateData.Success(it)
                })
        }
    }
}